import useUserStore from '@/store/modules/user'
import usePermissionStore from '@/store/modules/permission'
const userStore = useUserStore()
const routerStore = usePermissionStore()
export const baseURL = 'https://beta.paiduoduo.app/'


export const headers = {
  Authorization: userStore.token

}
export const formateDate = (date) => {
  return date.replace(/\//g, '-')
}

// 获取路径索引
export const getPathIndex = (parent, child) => {
  let routes = routerStore.routes
  // console.log('路由', routes)

  let childIndex = 0
  let parentIndex = 0
  if (parent && child) {
    parentIndex = routes.findIndex((item) => { return item.path == parent })
    // console.log('父级索引', parentIndex)
    let filterArr = routes[parentIndex].children
    let childRoutes = filterArr.filter((item) => { return item.is_show == 1 })
    childIndex = childRoutes.findIndex((item) => { return item.path == `${parent}${child}` })
    // console.log('子级索引', childIndex)
    return [parentIndex, childIndex]

  }
  if (parent && !child) {
    parentIndex = routes.findIndex((item) => { return item.path == parent })
    return parentIndex
  }

}
let _debounceTimeout = null
export const debounce = (fn, delay = 500) => {
  clearTimeout(_debounceTimeout);
  _debounceTimeout = setTimeout(() => {
    fn();
  }, delay);
}